package net.wofly.cashier.dishes.validator;

import net.wofly.cashier.dishes.domain.DailyCommodityNum;
import org.springframework.util.StringUtils;

/**
 * Created by LiuJianbo on 2017/10/18.
 */
public class DishesValidator {
    
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");
    
    public static String validateCommodityID(String commodityID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(commodityID)) {
            stringBuffer.append("菜品ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateGetAllDishesParams(Integer status, String commodityTypeID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (status.intValue() != 1 && status.intValue() != 0 && status.intValue() != -1) {
            stringBuffer.append("status值不正确！").append(lineSeparator);
        }
        if (StringUtils.isEmpty(commodityTypeID)) {
            stringBuffer.append("菜品类型ID(commodityTypeID)不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateGetValidDishesNumParams(String commodityID, Long currDate) {
        StringBuffer stringBuffer = new StringBuffer();
        validateCommodityID(commodityID);
        if (currDate == null) {
            stringBuffer.append("日期（currDate）不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    
    public static String validateSetDailyDishesNumParams(DailyCommodityNum dailyCommodityNum) {
        StringBuffer stringBuffer = new StringBuffer();
        if (dailyCommodityNum == null) {
            stringBuffer.append("dailyCommodityNum对象不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(dailyCommodityNum.getCommodityID())) {
                stringBuffer.append("菜品ID(CommodityID)不能为空！").append(lineSeparator);
            }
            if (dailyCommodityNum.getNum() == null || dailyCommodityNum.getNum() < 0) {
                stringBuffer.append("菜品可卖数量不能为空，并且可买数量不能小于零！").append(lineSeparator);
            }
            if (dailyCommodityNum.getSetDate() == null) {
                stringBuffer.append("设置日期不能为空！").append(lineSeparator);
            }
        }
        
        return stringBuffer.toString();
    }
    
    
}
